package logic

import (
	"context"
	"fmt"
	"zero_demo06_rpc_api/user/rpc/dao"
	"zero_demo06_rpc_api/user/rpc/internal/svc"
	"zero_demo06_rpc_api/user/rpc/types/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserInfoByIdLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserInfoByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserInfoByIdLogic {
	return &UserInfoByIdLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserInfoByIdLogic) UserInfoById(in *user.UserInfoRequest) (*user.UserInfoResponse, error) {
	// todo: add your logic here and delete this line

	userEntity, err := dao.Use(l.svcCtx.MySqlDb).UserEntity.WithContext(l.ctx).Where(dao.Use(l.svcCtx.MySqlDb).UserEntity.ID.Eq(in.UserId)).First()
	fmt.Println(userEntity, "获取到的数据")
	return &user.UserInfoResponse{
		UserId:   userEntity.ID,
		Username: userEntity.Username,
	}, err
}
